package StudyCode.summary.mycollection;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SubtractsTheTwoArraysTogether {
	public static void main(String[] argv) {
		double[] a = new double[]{34.45, 35.45, 36.67, 37.78, 37.0000,
				37.1234, 67.2344, 68.34534, 69.87700};
		double[] b = new double[]{34.45, 35.45, 36.67, 37.78, 37.0000,
				37.1234, 67.2344, 68.34534, 69.87700};
		System.out.println("两个数组一一对应相加");
		System.out.println(Arrays.toString(subtract(a, b)));
	}

	public static double[] subtract(double[] a, double[] b) {
		double[] ans = copy(a);
		for (int i = 0; i < a.length; i++) {
			ans[i] -= b[i];
		}
		return (ans);
	}

	public static double[] copy(double[] array) {
		double[] result;
		result = new double[array.length];
		System.arraycopy(array, 0, result, 0, array.length);
		return result;
	}
}
